'use strict';
import Base from './base.js';
export default class extends Base {
	
	/*
	**通用方法写在此处
	**2017.3.13
	**黄
	*/


	//获取部门、职位和职位对应职称
	async getdplistAction(){
		if (this.isPost) {
			let zwid = this.post('id');
			console.log(zwid);
			let zcpid = await this.model('or_department').where({id:this.shop_userinfo.departmentid}).getField('pid');
			let zclist = await this.model('or_position').where({floor:2,positionid:zwid,departmentid:zcpid[0]}).select();
			if (think.isEmpty(zclist)) {
				return this.fail({info:'无职称'});
			}else{
				return this.json(zclist);
			}
		}else{
			let pid = await this.model('or_department').where({id:this.shop_userinfo.departmentid}).getField('pid', true);
			let plist = await this.model('or_position').where({floor:1,departmentid:pid}).select();
			let data = {
				'plist':plist,
			}
			return this.json(data);
		}

	}
	
	//获取七牛上传图片的验证token
	async gettokenAction(){
		
		let qiniu = require("qiniu");

		//需要填写你的 Access Key 和 Secret Key
		qiniu.conf.ACCESS_KEY = this.config('qiniu.ACCESS_KEY');
		qiniu.conf.SECRET_KEY = this.config('qiniu.SECRET_KEY');
		//要上传的空间
		let bucket = this.config('qiniu.BUCKET');
		
		//构建上传策略函数
		function uptoken(bucket, key) {
		  let putPolicy = new qiniu.rs.PutPolicy(bucket);
		  return putPolicy.token();
		}
		//生成上传 Token
		let token = uptoken(bucket);
		let data = {'uptoken':token};
		return this.json(data);	
	}
	
	
	//获取左侧的分类列表
	async getMenuAction(){
		let mlist = await this.model('menu').where({status:1,is_hidden:0}).select();
		return this.json(mlist);
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
}